package com.cwl.pulgins.handle;

import com.cwl.pulgins.domain.Table;
import com.cwl.pulgins.utils.VelocityUtils;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.app.VelocityEngine;

import java.io.StringWriter;
import java.util.Properties;

/**
 * @program: pulgin
 * @description:
 * @author: ChenWenLong
 * @create: 2019-09-03 16:02
 **/
public class SqlGenerator {

    public String generate(Table table){
        VelocityContext velocityContext = new VelocityContext();
        velocityContext.put("table",table);
        Properties p = new Properties();
        p.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, "D:\\");
        Velocity.init(p);
        Template template = Velocity.getTemplate("create_table.vm");
        StringWriter stringWriter = new StringWriter();
        template.merge(velocityContext, stringWriter);
        template.process();
        return stringWriter.toString();
    }

    public static void main(String[] args) {
        Properties p = new Properties();
        p.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, "D:\\");
        Velocity.init(p);
        Template template = Velocity.getTemplate("create_table.vm");
        System.out.println(template);
    }
}
